package logic

import (
	"context"
	"hotel/model/redis"
	"math/rand"
	"time"

	"hotel/hotelrpc/hotelrpc"
	"hotel/hotelrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendsmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendsmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendsmsLogic {
	return &SendsmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendsmsLogic) Sendsms(in *hotelrpc.SendsmsRequest) (*hotelrpc.SendsmsResponse, error) {
	// todo: add your logic here and delete this line
	code := rand.Intn(9000) + 1000

	//sendsms, err := pkg.Sendsms(in.Tel, strconv.Itoa(code))
	//if err != nil {
	//	return nil, err
	//}
	//if *sendsms.Body.Code != "OK" {
	//	return nil, fmt.Errorf(*sendsms.Body.Message)
	//}
	redis.Client.Set("sendsms"+in.Source+in.Tel, code, time.Minute*5)

	return &hotelrpc.SendsmsResponse{}, nil
}
